<?php
function write_setting($setting){
	global $db;
	foreach($setting as $k=>$v){
		if($db->result_first("SELECT COUNT(*) FROM order_setting WHERE `key`='$k'")){	
			$db->query("UPDATE order_setting set `value`='$v' WHERE `key`='$v'");
		}else{
			$db->query("INSERT INTO order_setting(`key`, `value`) VALUES('$k', '$v')");
		}
	}
}

function read_setting($key=''){
	global $db;
	if($key == ''){
		$query = $db->query("SELECT * FROM order_setting");
		$setting = array();
		while($row = $db->fetch_array($query)){
			$setting[$row['key']] = $row['value'];
		}
		return $setting;
	}else{
		return $db->fetch_first("SELECT * FROM order_setting WHERE key='$key'");
	}
}

?>